package com.wxyzz.satserver.friend.controller;


import com.wxyzz.common.core.common.R;
import com.wxyzz.common.core.utils.UserUtils;
import com.wxyzz.satserver.friend.entity.vo.FriendVO;
import com.wxyzz.satserver.friend.service.IFriendService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;


import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wyz
 * @since 2024-11-14
 */
@RestController
@RequestMapping("/friend")
@Api(tags ="好友api")
@CrossOrigin
public class FriendController {

    @Resource
    private IFriendService friendService;
    @GetMapping("/getFriendList")
    @ApiOperation(value = "查询自已的好友列表")
    public R getFriendList(){
        //获得用户的Id 查询他的好友
        int id = UserUtils.getUid();
        List<FriendVO> friendVOList = friendService.selectFriendList(id);
        return R.ok(friendVOList);
    }
    @GetMapping("/findFriend")
    @ApiOperation(value = "查询用户")
    public R findFriend(String name){
        //找出包含 friendName 的⽤⼾信息. 抛出掉 selfUserId 本⾝和他的好友
        int id = UserUtils.getUid();
        return R.ok(friendService.findFriend(id,name));
    }

    @GetMapping("/addFriend")
    @ApiOperation(value = "发送添加好友请求")
    public R addFriend(int friendId, String reason, HttpServletRequest req ){
        friendService.addFriend(friendId,reason,req);
        return R.ok();
    }
    @GetMapping("/getFriendRequest")
    @ApiOperation(value = "获取到添加好友请求(离线)")
    public R getFriendRequest(HttpServletRequest req){
       return R.ok(friendService.getFriendRequest(req));
    }

    @GetMapping("/acceptFriend")
    @ApiOperation(value = "确认添加好友请求")
    public R acceptFriend(int friendId,HttpServletRequest req){
        friendService.acceptFriend(friendId,req);
        return R.ok();
    }

    @GetMapping("/rejectFriend")
    @ApiOperation(value = "忽略添加好友请求")
    public R rejectFriend(int friendId, HttpServletRequest req){
        friendService.rejectFriend(friendId,req);
        return R.ok();
    }

}
